/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Classe;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Ellipse2D;
import javax.swing.JButton;
import javax.swing.JFrame;

/**
 *
 * @author gladson
 */
public class RoundButton extends RoundedCornerButton {
  public RoundButton(String text) {
    super(text);
    setFocusPainted(false);
    initShape();
  }
  @Override public Dimension getPreferredSize() {
    Dimension d = super.getPreferredSize();
    d.width = d.height = Math.max(d.width, d.height);
    return d;
  }
  protected void initShape() {
    if(!getBounds().equals(base)) {
      base = getBounds();
      shape = new Ellipse2D.Float(0, 0, getWidth()-1, getHeight()-1);
      border = new Ellipse2D.Float(focusstroke, focusstroke,
                                   getWidth()-1-focusstroke*2,
                                   getHeight()-1-focusstroke*2);
    }
  }

  public static void main(String args[]) {
    JFrame ventana = new JFrame( "Tutorial de Java, Swing" );
    ventana.getContentPane().setLayout( new FlowLayout() );
    ventana.getContentPane().setBackground( Color.yellow );

    ventana.addWindowListener( new WindowAdapter() {
      public void windowClosing( WindowEvent evt ) {
        System.exit( 0 );
        }
      } );

    // Se crea el botón y se le pone fondo rojo
    JButton boton = new RoundButton( "Boton" );
    boton.setBackground( Color.blue );
    // Se incorpora a la ventana
    ventana.getContentPane().add( boton );
    ventana.setSize( 300,150 );
    ventana.show();
    }
}

